﻿using Newtonsoft.Json;
using System.Collections.Generic;
using System.Linq;

namespace Yyyg.WebUI.Models
{
    public class PostResult
    {
        /// <summary>
        /// 指示是否成功
        /// </summary>
        public bool Isucc { get; set; }

        /// <summary>
        /// 包含的错误信息
        /// </summary>
        public List<string> Errors { get; set; }

        /// <summary>
        /// 主要错误信息
        /// </summary>
        public string ErrorMsg { get; set; }

        /// <summary>
        /// 有关错误的状态码,由接口自行约定
        /// </summary>
        public int ErrorCode { get; set; } = 0;

        public PostResult()
        {
            Errors = new List<string>();
            Isucc = false;
        }

        public PostResult(bool isucc, string errorMsg = "", params string[] ers) : this()
        {
            this.Isucc = isucc;
            this.ErrorMsg = errorMsg;
            this.Errors = ers.ToList();
        }

        public string ToJson()
        {
            return JsonConvert.SerializeObject(this);
        }

        public static PostResult JsonParse(string json)
        {
            return JsonConvert.DeserializeObject<PostResult>(json);
        }
    }
}